import decimal
from openpyxl.styles import fills,colors,NamedStyle,Font,Side,Border,PatternFill,Alignment,Protection
import sys
import mpmath
import loger

log=loger.Logger('cjpb',StreamLevel='debug',FileLevel='info').logger

titleH="新街中学2025年秋期中测试"
titleF="成绩评比签字确认表"
cppjttj=False #参评平均分统计
DecimalPoint=2 #小数点位数
rangeByGroup=False #分组排名

ScoreConversion=True        #折算成绩
# ScoreConversion=False     #原始成绩

MissingExamination = 0      #缺考处理 None：忽略， 0：0分处理
MissingExamination = None   #缺考处理 None：忽略， 0：0分处理
group={ 
        "七年级":[(109,116),(110,111,112,113,114,115)],
        "八年级":[(103,),(101,102,104,105,106,107,108)],
        "九年级":[(98,),(95,96,97,99,100, "启航")],

		}

# km={            "七年级":["语文","数学","英语","道法","历史","物理","化学","地理","生物"],
#                 "八年级":["语文","数学","英语","道法","历史","物理","化学","地理","生物"],
#                 "九年级":["语文","数学","英语","道法","历史","物理","化学","地理","生物"]
#     }

# km={    
#         "七年级":["语文","数学","英语","道法","历史","地理","生物"],
#         "八年级":["语文","数学","英语","道法","历史","地理","生物","物理"],
# 		}


km={    "七年级":["语文","数学","英语","道法","历史","地理","生物"],
        "八年级":["语文","数学","英语","道法","历史","地理","生物","物理"],
        "九年级":["语文","数学","英语","道法","历史","物理","化学"]
		}

zkm=[]
for k in km:
        zkm=zkm+km[k]
zkm=list(set(zkm))
subjectAlias={
    "道法":["道德与法治","政治"],
    "英语":["外语"],
    "考生号":["考号"]
}

mcz=["第一名","第二名","第三名","第四名","第五名","第六名","第七名","第八名","第九名","第十名"]
#以实考人数计算
cprs={}
# cprs={	
# 		"101":75
# 		,"102":74
# 		,"103":74
# 		,"104":71
# 		,"105":73
# 		,"106":72
#         ,"88":69    #67 
#         ,"90":63
#         ,"91":64
#         ,"92":60
#         ,"93":45
#         ,"94":67
#         ,"95":65
#         ,"96":64
#         ,"97":64
#         ,"98":54
#         ,"99":64
#         ,"100":74
#         ,"801":66
#         ,"802":62
#         ,"806":61
# 		}
cprs_e={}
# cprs_e={    #特殊参评人数
#     "84语文":168
#     ,"84地理":68
#     ,"87生物":70
#     ,"87地理":70
#     } 



alias={
		"3":"志成",
		"1":"启光",
		"4":"弘毅",
		"5": "鸿图",
		"6": "自强",
        "221":"22级1",
		"222":"22级2",
		"223":"22级3",
		"224":"22级4",
		"225":"22级5",
        "226":"22级6",
        "227":"22级7",
        "801" : "启航",
        "802" : "继光",
        "806" : "凌云",

		}



# def zh(km,df):  #不折算
#     try:
#         df=float(df)
#     except :
#         print(km,"分数异常")
#         sys.exit(0)
#     return df






def zh(km,df):
    if(df=="" or df=="None" or df==None):
        return None
    try:
        dfx=float(df)
    except :
        print(km,f"分数异常:  {df}")
        sys.exit(0)
    finally:
        dfx=None
    df=mpmath.mpf(df)

    if(ScoreConversion): 
        if (km == "物理"):
            return df * mpmath.mpf('0.5')
        if (km == "化学" or km == "地理"):
            return df * mpmath.mpf('0.3')
        if (km == "道法"  or km == "历史" or km == "生物"):
            return df * mpmath.mpf('0.4')
        if (km == "信息" or km == "音乐" or km == "美术"):
            if(df>=60):
                return 10
            else:
                return 0
        return df
    else:
        return df


# def zh(km,df):  #旧折分方法
#     try:
#         df=float(df)
#     except :
#         print(km,"分数异常")
#         sys.exit(0)
#     if (km == "物理"):
#         return df*0.8
#     if (km == "化学"):
#         return df*0.5
#     if (km == "道法" or km == "地理" or km == "历史" or km == "生物"):
#         if(df>=60):
#             return 10
#         else:
#             return int((df+5)/10)

#     return df


def getTotal(c,d,k):
    if str(c) not in cprs :
        cprs[str(c)]=0
    if("{0}{1}".format(c,k) in cprs_e):
        # print ("{0}{1}".format(c,k),cprs_e["{0}{1}".format(c,k)])
        return cprs_e["{0}{1}".format(c,k)]
    t=max(len(d),cprs[str(c)])

    # print("{0}\t{1}\t{2}".format(cprs[str(c)],len(d),t))
    # print(max(t,len(d),cprs[str(c)]))

    if(len(d)>cprs[str(c)] and cprs[str(c)]>0 ):
        print("{0}{1}实考{2}人，参评{3}人".format(c,k,len(d),t))
    return max(t,len(d),cprs[str(c)])



bd = Border(
    left=Side(border_style="thin",
                color='000000'),
    right=Side(border_style="thin",
                color='000000'),
    top=Side(border_style="thin",
                color='000000'),
    bottom=Side(border_style="thin",
                color='000000')
                )
alignment=Alignment(horizontal='center',#水平'center', 'centerContinuous', 'justify', 'fill', 'general', 'distributed', 'left', 'right'
            vertical='center',#垂直'distributed', 'bottom', 'top', 'center', 'justify'
            text_rotation=0,#旋转角度0~180
            wrap_text=False,#文字换行
            shrink_to_fit=True,#自适应宽度，改变文字大小,上一项false
            indent=0)
alignment1=Alignment(horizontal='left',#水平'center', 'centerContinuous', 'justify', 'fill', 'general', 'distributed', 'left', 'right'
            vertical='center',#垂直'distributed', 'bottom', 'top', 'center', 'justify'
            text_rotation=0,#旋转角度0~180
            wrap_text=False,#文字换行
            shrink_to_fit=True,#自适应宽度，改变文字大小,上一项false
            indent=0)

fontTitle=Font(bold=True,size=24)
# a=100
# b=5
# print(f"{a:.{b}f}")

log.info("baseDataText")
